package com.afinal.intelligencetrash.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.afinal.intelligencetrash.R;


/**
 * Created by 厂里帅小伙 on 2/25 0025.
 */

public class WaitingDialog extends Dialog {

    private TextView textView;
    private ProgressBar progressBar;
    public WaitingDialog(Context context){
        super(context, R.style.DialogTheme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    private void init() {
        setContentView(R.layout.waiting_dialog_layout);
        textView = (TextView) findViewById(R.id.textView);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
    }

    public void setTextView(String text){
        if(textView != null){
            textView.setText(text);
        }
    }


    public static class Builder{
        private String text;
        private boolean cancelable = true;
        private OnCancelListener onCancelListener;

        public Builder setText(String text){
            this.text = text;
            return this;
        }

        public Builder setCancelable(boolean cancelable){
            this.cancelable = cancelable;
            return this;
        }

        public Builder setOnCancelListener(OnCancelListener listener){
            this.onCancelListener = listener;
            return this;
        }

        public WaitingDialog build(Context context){
            WaitingDialog dialog = new WaitingDialog(context);
            dialog.create();
            dialog.setTextView(text == null ? "拼命加载中..." : text);
            dialog.setCancelable(cancelable);
            dialog.setOnCancelListener(onCancelListener);
            return dialog;
        }
    }


}
